package com.ddwl.order.config;

import com.alipay.api.AlipayClient;
import com.alipay.api.DefaultAlipayClient;
import com.github.binarywang.wxpay.config.WxPayConfig;
import com.github.binarywang.wxpay.service.WxPayService;
import com.github.binarywang.wxpay.service.impl.WxPayServiceImpl;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class PayConfig {

    @Value("${ddwl.alipay.appId}")
    private String appId;
    @Value("${ddwl.alipay.privateKey}")
    private String privateKey;
    @Value("${ddwl.alipay.publicKey}")
    private String publicKey;

    @Value("${ddwl.wxpay.mchId}")
    private String wxMchId;
    @Value("${ddwl.wxpay.appId}")
    private String wxAppId;
    @Value("${ddwl.wxpay.mchKey}")
    private String wxMchKey;
    @Value("${ddwl.wxpay.certPath}")
    private String keyPath;


    @Bean
    public AlipayClient defaultClient() {
        return new DefaultAlipayClient("https://openapi.alipay.com/gateway.do", appId, privateKey, "JSON", "UTF-8", publicKey, "RSA2");
    }

    @Bean
    public WxPayConfig wxPayConfig(){
        WxPayConfig payConfig = new WxPayConfig();
        payConfig.setAppId(wxAppId);
        payConfig.setMchId(wxMchId);
        payConfig.setMchKey(wxMchKey);
        payConfig.setKeyPath(keyPath);
        return payConfig;
    }

    @Bean
    public WxPayService wxPayService(WxPayConfig wxPayConfig){
        WxPayService wxPayService = new WxPayServiceImpl();
        wxPayService.setConfig(wxPayConfig);
        return wxPayService;
    }

}
